#include "promptview.h"
#include <QGraphicsTextItem>
#include <QGraphicsPixmapItem>
#include <QMouseEvent>
#include "toolkit.h"
#include <QLocale>

PromptView::PromptView(int itype,QString str,bool bNoButton,QWidget *parent) :
    QGraphicsView(parent),
    m_itype(itype),
    m_sel(-1)
{
    m_Scene = new QGraphicsScene(this);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setScene(m_Scene);
    m_Scene->setSceneRect(0.0, 0.0, 640.0, 360.0);

    m_textItem = m_Scene->addText(str , QFont("Helvetica", 10, QFont::Normal,FALSE));
    m_textItem->setPos(118, 80);
    m_textItem->setDefaultTextColor(Qt::black);
    m_textItem->setTextWidth(374);
    m_textItem->setZValue(2.0);

    m_bgItem = m_Scene->addPixmap(QPixmap(":/image/Prompt_bg.png", "png"));
    m_bgItem->setPos(0,0);
    m_bgItem->setZValue(0.0);

    switch(ToolKit::m_language)
    {
    case QLocale::Chinese:
    {
        m_yesBtnItem = m_Scene->addPixmap(QPixmap(":/image/prompt/324.png","png"));
    }
        break;
    case QLocale::HongKong:
    case QLocale::Taiwan:
    {
        m_yesBtnItem = m_Scene->addPixmap(QPixmap(":/image/prompt/3244.png","png"));
    }
        break;
    default:
    {
        m_yesBtnItem = m_Scene->addPixmap(QPixmap(":/image/prompt/32444.png","png"));
    }
        break;
    }

    m_yesBtnItem->setZValue(1.0);

    if(bNoButton)
    {
        switch(ToolKit::m_language)
        {
        case QLocale::Chinese:
        case QLocale::HongKong:
        case QLocale::Taiwan:
        {
            m_noBtnItem = m_Scene->addPixmap(QPixmap(":/image/prompt/122.png","png"));
        }
            break;
        default:
        {
            m_noBtnItem = m_Scene->addPixmap(QPixmap(":/image/prompt/12222.png","png"));
        }
            break;
        }

        m_noBtnItem->setPos(324,210);
        m_noBtnItem->setZValue(1.0);

        m_yesBtnItem->setPos(122,210);
    }
    else
    {
        m_yesBtnItem->setPos(222,210);
        m_noBtnItem = NULL;
    }
    setGeometry(0,0,640,360);


}

PromptView::~PromptView()
{
    delete m_bgItem;
    m_bgItem = NULL;

    if(m_noBtnItem != NULL)
    {
        delete m_noBtnItem;
        m_noBtnItem = NULL;
    }
    delete m_Scene;
    m_Scene = NULL;
}

void PromptView::mousePressEvent(QMouseEvent *event)
{
    if(m_yesBtnItem->isUnderMouse())
    {
        emit select(m_itype,1);
    }
    else if(m_noBtnItem != NULL && m_noBtnItem->isUnderMouse())
    {
        emit select(m_itype,0);
    }
}
